/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.neusoft.parsing;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;

import com.neusoft.ae.Dog;
import com.neusoft.util.myannotation.MyBean;
import com.neusoft.util.myannotation.MyMethodInfo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AnnotationParsing {

    public static void main(String[] args) {
        ClassLoader loader = AnnotationParsing.class.getClassLoader();
        URL resource = loader.getResource("com/neusoft");
        System.out.println(resource);
    }

    public static void main2(String[] args) {
        try {
            Class clazz = Class.forName("com.neusoft.ae.Dog");
            MyBean myBean = (MyBean) clazz.getAnnotation(MyBean.class);
            System.out.println(myBean.beanName());
            Dog dog = (Dog) clazz.getDeclaredConstructor().newInstance();
            System.out.println(dog);
            ApplicationContext context = new AnnotationConfigApplicationContext();

        } catch (Exception exception) {

        } finally {

        }
    }

    public static void main1(String[] args) {
        try {
            for (Method method :
                    AnnotationParsing.class
                            .getClassLoader()
                            .loadClass(("com.neusoft.ae.AnnotationExample"))
                            .getMethods()) {
                // checks if MethodInfo annotation is present for the method
                if (method.isAnnotationPresent(MyMethodInfo.class)) {
                    // iterates all the annotations available in the method
                    for (Annotation anno : method.getDeclaredAnnotations()) {
                        System.out.println("Annotation in Method " + method + ":" + anno);
                    }
                    MyMethodInfo methodAnno = method.getAnnotation(MyMethodInfo.class);
                    if (methodAnno.revision() == 1) {
                        System.out.println("Method with revision no 1 = " + method);
                    }
                }
            }
        } catch (Exception e) {

        }
    }
}
